import { ArticleTypes } from "redux/constants";

export const Creators = {
  // 文章列表
  getListRequest: ({ page, limit }) => ({
    type: ArticleTypes.GET_LIST_REQUEST,
    payload: { page, limit },
  }),
  getListSuccess: (data) => ({
    type: ArticleTypes.GET_LIST_SUCCESS,
    payload: data,
  }),
  getListFailure: (error) => ({
    type: ArticleTypes.GET_LIST_FAILURE,
    payload: error,
  }),
  // 发布文章
  publishRequest: ({ token, title, content }) => ({
    type: ArticleTypes.PUBLISH_REQUEST,
    payload: { token, title, content },
  }),
  publishSuccess: (data) => ({
    type: ArticleTypes.PUBLISH_SUCCESS,
    payload: data,
  }),
  publishFailure: (error) => ({
    type: ArticleTypes.PUBLISH_FAILURE,
    payload: error,
  }),
  // 编辑文章
  editRequest: ({ token, article_id, values }) => ({
    type: ArticleTypes.EDIT_REQUEST,
    payload: { token, article_id, values },
  }),
  editSuccess: (data) => ({
    type: ArticleTypes.EDIT_SUCCESS,
    payload: data,
  }),
  editFailure: (error) => ({
    type: ArticleTypes.EDIT_FAILURE,
    payload: error,
  }),
};
